package com.fjd.mapper;

import com.fjd.dto.OrderDTO;
import com.fjd.entity.SalesOrder;
import com.fjd.vo.OrderVO;
import org.apache.ibatis.annotations.*;
import org.springframework.core.annotation.Order;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface SalesOrderMapper {

    void insert(SalesOrder salesOrder);

    /**
     * 根据用户id和订单状态查询订单
     * @return
     */
    List<OrderVO> list(OrderDTO orderDTO);

    OrderVO select(String orderId);

    @Select("select * from sales_order where order_id = #{orderId}")
    SalesOrder getById(String orderId);

    @Update("update sales_order set order_status = #{status} where order_id = #{orderId}")
    void updateStatus(String orderId, String status);

    @Update("update sales_order set address_id = #{addressId} where order_id = #{orderId}")
    void setAddress(String addressId, String orderId);

    @Select("select * from sales_order where order_status = #{status} and modified_date < #{time}")
    List<SalesOrder> getByStatusAndTime(String status, LocalDateTime time);

    void update(SalesOrder salesOrder);

    @Delete("delete from sales_order where order_id = #{orderId}")
    void deleteById(String orderId);

    @Select("select count(*) from sales_order where reference_id = #{anchorId}")
    String getLiverOrderCount(String anchorId);

    @Select("select sum(order_total) from sales_order where reference_id = #{anchorId}")
    BigDecimal getLiverAmountCount(String anchorId);
}
